# -*- coding:utf-8 -*-
# /exts.py    数据库对象及表文件

from flask_sqlalchemy import SQLAlchemy
import pymysql


pymysql.install_as_MySQLdb()
db = SQLAlchemy()


class Task(db.Model):    # 评测任务表
    __tablename__ = "task"
    task_id = db.Column(db.Integer, primary_key = True)
    prob_id = db.Column(db.Integer)
    language = db.Column(db.String(10))
    code = db.Column(db.Text)


class Setting(db.Model): # 配置表
    __tablename__ = "setting"
    key = db.Column(db.String(256), primary_key = True)
    value = db.Column(db.Text)


class Problem(db.Model): # 题目表
    __tablename__ = "problem"
    id = db.Column(db.Integer, primary_key = True, autoincrement = True)
    name = db.Column(db.String(128))
    description_markdown = db.Column(db.Text)
    description_html = db.Column(db.Text)
    answer_markdown = db.Column(db.Text)
    answer_html = db.Column(db.Text)


class User(db.Model):
    __tablename__ = "user"
    username = db.Column(db.String(128), primary_key = True)
    password = db.Column(db.String(256))


class Record(db.Model): # 评测记录表
    __tablename__ = "record"
    id = db.Column(db.Integer, primary_key = True)
    user = db.Column(db.String(128))
    prob_id = db.Column(db.Integer)
    language = db.Column(db.String(10))
    code = db.Column(db.Text)
    status = db.Column(db.String(10))
    score = db.Column(db.Integer)
    result = db.Column(db.Text)
    time = db.Column(db.String(50))


class Discuss(db.Model):
    __tablename__ = "discuss"
    id = db.Column(db.Integer, primary_key = True, autoincrement = True)
    title = db.Column(db.String(128))
    content = db.Column(db.Text)
    time = db.Column(db.String(50))
    user = db.Column(db.String(128))
    comment = db.Column(db.Text)
    board = db.Column(db.String(128))


class Comment(db.Model):
    __tablename__ = "comment"
    id = db.Column(db.Integer, primary_key = True, autoincrement = True)
    content = db.Column(db.Text)
    user = db.Column(db.String(128))
    time = db.Column(db.String(50))


class Board(db.Model):
    __tablename__ = "board"
    name = db.Column(db.String(128), primary_key = True)
    discuss = db.Column(db.Text)
